/**
 * Created by root on 2017-05-18.
 */
$(function(){
    var user = JSON.parse( sessionStorage.getItem("user") );
    if (!user) {
        window.location.href = "../html/login.html";
    } else {
        // 初始化 页面
        $.post(config.devUrl + "/investsUser/queryInversts.json",
            {
                userId: user.id,
                status: 1
            },
            function(result){
                if (result.status == config.success) {
                    //result.data.goodsJson =  JSON.parse( result.data.goodsJson );
                    // 渲染页面
                    console.info(result)
                    var html =  template('inverstsScript',  result );
                    $("#inverstsList").html(html);
                    // 添加投资总收益
                    var rates = null;
                    for (var i=0; i<result.data.length; i++) {
                        for (var j=0; j<result.data[i].investsUserDetailVos.length; j++) {
                            rates += result.data[i].investsUserDetailVos[j].amountAll;
                        }
                    }
                    if (rates) {
                        $(".income-num").html(rates);
                    }
                    // 存session
                    //var goodsString = JSON.stringify(result);
                    //sessionStorage.setItem("goodsCart", goodsString);
                } else {
                    alert(result.msg)
                }
            }, "json");

        // 购买投资
        $("#sellInvests").on("click", function(){
            alert("购买投资没有页面");
        });


    }

});

